package com.csy.repair.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.repair.entity.AjRepair;
import com.csy.repair.service.AjRepairService;

/**
 * 报修
 */
@RestController
@RequestMapping("/system/repair")
public class AjRepairController extends BaseController {

	@Resource
	private AjRepairService ajRepairService;

	/**
	 * 统计报修数量
	 * 
	 * @return
	 */
	@GetMapping("/countRepair")
	public BaseResponse<Integer> countRepair() throws Exception {
		int repairNum = ajRepairService.countRepair();
		return BaseResponse.success(repairNum);
	}

	/**
	 * 查询报修集合
	 * 
	 * @param ajRepair
	 * @return
	 */
	@GetMapping("/list")
	public PageResult list(AjRepair ajRepair) throws Exception {
		startPage();
		List<AjRepair> list = ajRepairService.selectRepairList(ajRepair);
		return getData(list);

	}

	/**
	 * 查询报修信息
	 * 
	 * @param repairId
	 * @return
	 */
	@GetMapping(value = "/{repairId}")
	public BaseResponse<AjRepair> getInfo(@PathVariable Long repairId) throws Exception {
		return BaseResponse.success(ajRepairService.selectRepairById(repairId));
	}

	/**
	 * 添加报修信息
	 * 
	 * @param ajRepair
	 * @return
	 */
	@PostMapping
	public BaseResponse<Integer> add(@RequestBody AjRepair ajRepair) throws Exception {
		return toAjax(ajRepairService.add(ajRepair));
	}

	/**
	 * 删除
	 * 
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/{ids}")
	public BaseResponse<Integer> delByIds(@PathVariable("ids") List<Long> ids) throws Exception {
		return toAjax(ajRepairService.delByIds(ids));
	}

}
